do "E:/ReplicateBuild/02_code/00_environment/00_set_environment.do"


use "$basedata/estimationdata/All_T_J/principal_pref_est_data.dta", clear

egen sidx = group(ncerdc_schlcode)

gen application_outcome = .
replace application_outcome = 0 if inlist(application_outcome_category,"negative_assessment","negative_later_signal")
replace application_outcome = 1 if inlist(application_outcome_category,"neutral","middle_assessment")
replace application_outcome = 2 if inlist(application_outcome_category,"positive_assessment")

replace application_outcome = 3 if inlist(application_outcome_category,"interview")
replace application_outcome = 4 if inlist(application_outcome_category,"hired")
replace application_outcome = 5 if inlist(application_outcome_category,"offer_declined")

drop if application_outcome==.

gen totVA = va_ma_preY_dev + mu_jt_preY_mean_s_ma
gen totVA_T1 = va_ma_preY_dev_T1 + mu_jt_preY_mean_s_ma_T1

bys jtidx: egen min_rating = min(application_outcome)
bys jtidx: egen max_rating = max(application_outcome)
drop if min_rating==max_rating

global logitlist = "totVA totVA_T1 exp_2 exp_2_T1 exp_4 exp_4_T1 exp_6 exp_6_T1 exp_missing exp_missing_T1 masters masters_T1 black black_teachXblack_share black_T1 black_teachXblack_share_T1 hispanic hispanic_T1 hisp_teachXhisp_share hisp_teachXhisp_share_T1 female female_T1 sex_missing sex_missing_T1 race_missing race_missing_T1 has_va_ma_preY_dev has_va_ma_preY_dev_T1 titleI praxis praxis_T1 praxisMissing praxisMissing_T1 grad_degree grad_degree_T1 grad_degreeMissing grad_degreeMissing_T1 certified certified_T1 certifiedMissing certifiedMissing_T1 licensed licensed_T1 licensedMissing licensedMissing_T1"


rologit application_outcome $logitlist , group(jtidx)

foreach var in $logitlist {
	gen b1_`var' = _b[`var']
	gen se1_`var' = _b[`var']
}
	
cap drop min_rating max_rating

drop if application_outcome_category=="neutral"

bys jtidx: egen min_rating = min(application_outcome)
bys jtidx: egen max_rating = max(application_outcome)
drop if min_rating==max_rating
	
rologit application_outcome $logitlist , group(jtidx)

foreach var in $logitlist {
	gen b2_`var' = _b[`var']
	gen se2_`var' = _b[`var']
}

save "$temp/ranked_ordered_logit_results", replace
	
	
use "$temp/ranked_ordered_logit_results", clear

preserve
keep b1*
keep if _n==1
outsheet using "$temp/rank_ordered_logit_all.csv", comma replace nonames
restore

preserve
keep b2*
keep if _n==1
outsheet using "$temp/rank_ordered_logit_restricted.csv", comma replace nonames
restore

